<template>
  <div id="main2">
    <div v-if="!params">
      <el-empty :image-size="500"></el-empty>
    </div>
    <div v-else style="height: 690px; overflow: auto; margin-top: 0.2rem">
      <div>
        <p class="title">{{ title }}</p>
        <div
          style="
            margin-left: 70vw;
            margin-bottom: 0.2rem;
            font-size: 0.26rem;
            color: #131313;
          "
        >
          单位：{{ tableData[0].unit }}
        </div>
      </div>

      <el-table
        :data="tableData"
        style="width: 90%; margin-left: 5%; font-size: 0.26rem; color: #131313"
        border
        :row-style="{
          height: '40px',
          'line-height': '50px !important',
          'text-align': 'center',
        }"
        :cell-style="{
          padding: '0',
          'padding-top': '3px',
          'line-height': '50px !important',
          'text-align': 'center',
        }"
        :row-class-name="tableRowClassName"
        :header-cell-style="{
          fontWeight: 600,
          fontSize: '15px',
          color: '#000000 !important',
        }"
      >
        <el-table-column
          v-for="(item, index) in typeList"
          :key="index"
          :prop="item.prop"
          :label="item.label"
          align="center"
        >
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: "calculation",
  props: {
    // title: {
    // 	type: String,
    // 	default: '标题'
    // },
    // currentPage: {
    // 	type: Number,
    // 	default: 1
    // },
    // total: {
    // 	type: Number,
    // 	default: 10
    // },
  },
  data() {
    return {
      typeList: [
        {
          prop: "year_date",
          label: "日期",
        },
        {
          prop: "value",
          label: "数据",
        },
      ],
      tableData: [],
      data: [],
      params: null,
      url: {
        getComputeChart: "/web/program/getComputeChart",
      },
      title: "",
    };
  },
  created() {},
  methods: {
    async getComputeChart(params) {
      this.tableData = [];
      this.params = params;

      let value3 = "";

      this.title = ` ${params.param1.area}${params.param1.child_kind}与${params.param2.area}${params.param2.child_kind}${value3}对比`;
      this.typeList = [
        {
          prop: "year_date",
          label: "日期",
        },
        {
          prop: "value1",
          label: params.param1.child_kind,
        },
        {
          prop: "value2",
          label: params.param2.child_kind,
        },
        {
          prop: "value3",
          label: "差",
        },
        {
          prop: "value4",
          label: "比值",
        },
      ];
      let res = await this.$http.post(this.url.getComputeChart, this.params);
      this.tableData = res.data.result;
    },

    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 !== 0) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "";
      }
    },
    resetComputeChart() {
      this.tableData = [];
    },
  },
};
</script>

<style lang="scss" scoped>
.el-table .warning-row {
  background: #e8f4ff !important;
}
.title {
  padding-top: 0.06rem;
  text-align: center;
  font-size: 0.3rem;
  color: #000000;
  font-weight: 600;
}
#main2 {
  width: 100%;
  // height: 71vh;
  padding-bottom: 3vh;
}
</style>
